package com.punai.customer.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.domain.TreeBo;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.customer.domain.CusLinkMaterialStaCus;
import com.punai.customer.domain.vo.LinkCusStaVo;
import com.punai.customer.domain.vo.MaterialStaCusVo;
import com.punai.customer.domain.vo.MaterialVo;
import com.punai.customer.service.ICusLinkMaterialStaCusService;
import com.punai.customer.service.ICusMaterialCuChapterService;
import com.punai.customer.service.ICusMaterialCuItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标准材料与客户材料的对应Controller
 * 
 * @author zxw_
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/cus/linkStaCus")
public class CusLinkMaterialStaCusController extends BaseController
{
    @Autowired
    private ICusLinkMaterialStaCusService cusLinkMaterialStaCusService;

    @Autowired
    private ICusMaterialCuChapterService cusMaterialCuChapterService;
    @Autowired
    private ICusMaterialCuItemService cusMaterialCuItemService;

    /**
     * 查询标准材料与客户材料的对应列表
     */
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusLinkMaterialStaCus cusLinkMaterialStaCus)
    {
        startPage();
        List<CusLinkMaterialStaCus> list = cusLinkMaterialStaCusService.selectCusLinkMaterialStaCusList(cusLinkMaterialStaCus);
        return getDataTable(list);
    }


    /**
     * 新增标准材料与客户材料的对应
     */
    @PreAuthorize("@ss.hasPermi('cus:linkStaCusCL:add')")
    @Log(title = "标准材料与客户材料的对应", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialStaCusVo vo)
    {
        return toAjax(cusLinkMaterialStaCusService.insertLink(vo));
    }

    /**
     * 修改标准材料与客户材料的对应
     */
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:edit')")
    @Log(title = "标准材料与客户材料的对应", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusLinkMaterialStaCus cusLinkMaterialStaCus)
    {
        return toAjax(cusLinkMaterialStaCusService.updateCusLinkMaterialStaCus(cusLinkMaterialStaCus));
    }

    /**
     * 删除标准材料与客户材料的对应
     */
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:remove')")
    @Log(title = "标准材料与客户材料的对应", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(cusLinkMaterialStaCusService.deleteCusLinkMaterialStaCusById(id));
    }

    // 拉取存在的关联关系
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectUsedLink")
    public TableDataInfo selectUsedLink(LinkCusStaVo vo)
    {
        startPage();
        List<CusLinkMaterialStaCus> list = cusLinkMaterialStaCusService.selectUsedLink(vo);
        return getDataTable(list);
    }


    // 拉取标准费用项
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectStaMaterialTree")
    public AjaxResult selectStaMaterialTree()
    {
        List<TreeBo> treeBos = cusMaterialCuChapterService.selectTreeData();
        return AjaxResult.success(treeBos);
    }
    // 拉取标准费用项
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectStaMaterialList")
    public TableDataInfo selectStaMaterialList(MaterialVo vo)
    {
        return cusMaterialCuItemService.selectListData(vo);
    }

    // 拉取客户费用项
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectMaterialList")
    public TableDataInfo selectMaterialList(MaterialVo vo)
    {
        return cusMaterialCuItemService.selectMaterialList(vo);
    }

}
